package com.zhsj.OkeHomeConsumption.ui.fragment.minehome;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.ui.activity.PayAmountActivity;
import com.zhsj.OkeHomeConsumption.ui.activity.wallet.ClearEditText;

import java.math.BigDecimal;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.zhsj.OkeHomeConsumption.common.Constants.SHARED_PERFERENCE_USERINFO;

/**
 * author : Xingdx
 * <p>
 * time   : 2018/10/18
 * desc   : 补缴保证金金额输入页面
 */
public final class BailInputPriceActivity extends MyActivity {

    @BindView(R.id.price_edit)
    ClearEditText priceEdit;
    @BindView(R.id.price_text)
    TextView priceText;
    @BindView(R.id.price_button)
    Button priceButton;
    private String price;
    private String depositLow;

    private double priced = 0.0;

    //用户信息实体
    private FormalUserInfo userInfo = null;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_bailinputprice;
    }

    @Override
    protected int getTitleId() {
        return R.id.tb_inputprice_title;
    }

    @Override
    protected void initView() {
        userInfo = Hawk.get(Constants.SHARED_PERFERENCE_USERINFO);
    }

    @Override
    protected void initData() {
        Bundle bundle = getIntent().getExtras();
        price = getIntent().getStringExtra("price");


        double d = Double.parseDouble(price);
        BigDecimal bg = new BigDecimal(d);
        d = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        priceText.setText("￥" + d);

        depositLow = getIntent().getStringExtra("depositLow");
        double b = Double.parseDouble(depositLow);
        BigDecimal bag = new BigDecimal(b);
        priced = bag.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.price_button)
    public void onViewClicked() {
        String prices = priceEdit.getText().toString().trim();
        if (prices != null && !prices.isEmpty()) {
            if (Double.parseDouble(prices) > Double.parseDouble(price)) {
                toast("补缴金额不能大于剩余补缴金额");
                return;
            }
            if (priced != 0.0) {
                if (Double.parseDouble(prices) < priced) {
                    toast("缴纳金额不能小于最小缴纳金额");
                    return;
                }
            }

            startActivity(new Intent(this, PayAmountActivity.class).putExtra("pay_flage", 0).putExtra("price", prices)
                    .putExtra("usertype", String.valueOf(userInfo.getLifeUserDTO().getLifeType())));
            finish();
        }

    }

}